package operations;

import book.BookList;
import tools.BinarySearch;
import tools.NameComparator;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA
 * Description:查找图书
 * User:22954
 * Date:2024-01-12
 * Time:20:36
 */
public class FindOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
//        System.out.println("查找图书");
        NameComparator nameComparator = new NameComparator();
        bookList.getBooks().sort(nameComparator);
        System.out.print("Please enter the name of the book you are looking for:");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        BinarySearch binarySearch = new BinarySearch();
        int index = binarySearch.binarytpSearch(bookList.getBooks(), name);
        if (index < 0) {
            System.out.println("This book is not available!");
        } else {
            System.out.println(bookList.getBooks().get(index).toString());
        }
    }
}
